using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Mvc.Ajax;
using Lilium.Web.Mvc.AjaxControlToolkit;
using System.Web.UI;

namespace Samples.Controllers
{
	public class AutoCompleteController: Controller
	{
		public ActionResult GetCompletionList(CompletionListRequest request)
		{
			if (request == null)
				throw new ArgumentNullException("request");

			if (request.Count == 0)
			{
				request.Count = 10;
			}

			if (request.PrefixText == "xyz")
			{
				return Json(AutoCompleteExtender.CreateCompletionList(Enumerable.Empty<Pair>()));
			}

			Random random = new Random();
			List<string> items = new List<string>(request.Count);
			for (int i = 0; i < request.Count; i++)
			{
				char c1 = (char)random.Next(65, 90);
				char c2 = (char)random.Next(97, 122);
				char c3 = (char)random.Next(97, 122);

				items.Add(request.PrefixText + c1 + c2 + c3);
			}

			return Json(AutoCompleteExtender.CreateCompletionList(items));
		}

		//
		// GET: /AutoComplete/

		public ActionResult Index()
		{
			return View();
		}
	}
}
